package com.lsp.kotlingank.mainpage.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.lsp.base.utils.imageloader.WyImageLoader;
import com.lsp.data.bean.GankInfoList;
import com.lsp.kotlingank.R;
import com.lsp.lib_uikit.commonrecycler.rvitem.RvListItem;
import java.util.List;

/**
 * @author lsp
 * @created 2017/8/21 14:30
 */
public class GankInfoItem extends RvListItem<GankInfoList.GankInfo> {
  @BindView(R.id.imv_icon) ImageView imvIcon;
  @BindView(R.id.tv_title) TextView tvTitle;
  @BindView(R.id.tv_desc) TextView tvDesc;
  @BindView(R.id.tv_time) TextView tvTime;

  /**
   * 构造
   *
   * @param context context
   * @param attrs attrs
   */
  public GankInfoItem(Context context, AttributeSet attrs) {
    super(context, attrs);
  }

  @Override protected void onAttachData(GankInfoList.GankInfo data) {
    super.onAttachData(data);
    String type = data.getType();
    String desc = data.getDesc();
    String createdAt = data.getCreatedAt();
    List<String> images = data.getImages();
    tvTitle.setText(type);
    tvDesc.setText(desc);
    tvTime.setText(createdAt);
    String imageUrl = "";
    if (images != null && images.size() > 0) {
      imageUrl = images.get(0);
    }
    WyImageLoader.getInstance().display(getContext(), imageUrl, imvIcon);
  }

  @Override protected int onAttachView() {
    return R.layout.item_gank_info;
  }

  @Override protected void onFinishInflate() {
    super.onFinishInflate();
    ButterKnife.bind(this);
  }
}
